package com.egao.orderB.service.impl;

import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
import com.egao.orderB.biz.OceanCustomerPlanBiz;
import com.egao.orderB.biz.OtherFeeBiz;
import com.egao.orderB.entity.OceanCustomerPlan;
import com.egao.orderB.entity.OtherFee;
import com.egao.orderB.service.OceanCustomerPlanService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

//import com.egao.orderB.mapper.OceanCustomerPlanMapper;
//import javax.transaction.Transactional;

/**
 * 海运客户计划服务实现类
 * @author : Doman
 * @date : 2021-11-10 16:32:48
 * @version ：1.0
 */
@Service
public class OceanCustomerPlanServiceImpl /*extends ServiceImpl<OceanCustomerPlanMapper, OceanCustomerPlan> */implements OceanCustomerPlanService {

	@Autowired
	private OceanCustomerPlanBiz oceanCustomerPlanBiz;
	@Autowired
	private OtherFeeBiz otherFeeBiz;

  @Override
  public JsonResult list(PageResult2<T> page, OceanCustomerPlan oceanCustomerPlan, User loginUser)  throws Exception{
    return oceanCustomerPlanBiz.list(page,oceanCustomerPlan,loginUser);
  }

  @Override
  public JsonResult list(OceanCustomerPlan oceanCustomerPlan, User loginUser) {
    return JsonResult.ok().setData(oceanCustomerPlanBiz.list(oceanCustomerPlan,loginUser));
  }

  @Override
  public JsonResult listOpen(OceanCustomerPlan oceanCustomerPlan, User loginUser) {
//    OceanCustomerPlan oceanCustomerPlan2 = oceanCustomerPlanBiz.getById(oceanCustomerPlan);
    OtherFee otherFee = new OtherFee();
    otherFee.setTableId(oceanCustomerPlan.getId());
    otherFee.setTableName("chf_ocean_customer_plan");
    oceanCustomerPlan.setOtherFeeList(otherFeeBiz.list(otherFee, loginUser));
    return JsonResult.ok().put("data", oceanCustomerPlan);
  }

  @Override
  public JsonResult getById(OceanCustomerPlan oceanCustomerPlan) {
    return JsonResult.ok().setData(oceanCustomerPlanBiz.getById(oceanCustomerPlan));
  }

  @Transactional
  @Override
  public JsonResult save(OceanCustomerPlan oceanCustomerPlan, User loginUser) {
    if (oceanCustomerPlanBiz.save(oceanCustomerPlan, loginUser)) {
      return JsonResult.ok("添加成功");
    }
    return JsonResult.error("添加失败");
  }

  @Transactional
  @Override
  public JsonResult update(OceanCustomerPlan oceanCustomerPlan, User loginUser) {
    if (oceanCustomerPlanBiz.update(oceanCustomerPlan, loginUser)) {
      return JsonResult.ok("修改成功");
    }
    return JsonResult.error("修改失败");
  }

  @Transactional
  @Override
  public JsonResult remove(OceanCustomerPlan oceanCustomerPlan, User loginUser) {
    if (oceanCustomerPlanBiz.remove(oceanCustomerPlan, loginUser)) {
      return JsonResult.ok("删除成功");
    }
    return JsonResult.error("删除失败");
  }

  @Transactional
  @Override
  public JsonResult cancel(OceanCustomerPlan oceanCustomerPlan, User loginUser) {
    if (oceanCustomerPlanBiz.cancel(oceanCustomerPlan, loginUser)) {
      return JsonResult.ok("取消成功");
    }
    return JsonResult.error("取消失败");
  }

}
